package com.sz.sensor.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.mcxtzhang.swipemenulib.SwipeMenuLayout;
import com.sz.sensor.R;
import com.sz.sensor.entity.SimpleEntity;

import java.util.List;

public class MsgAdapter extends BaseQuickAdapter<SimpleEntity, BaseViewHolder> {
    public MsgAdapter() {
        super(R.layout.item_platform);
    }

    @Override
    protected void convert(BaseViewHolder helper, SimpleEntity item) {
        RoundedImageView roundedImageView = helper.getView(R.id.riv_header);
        roundedImageView.setImageResource(item.getImgId());
        helper.setText(R.id.tv_title, item.getTitle());
        helper.setText(R.id.tv_subtitle, item.getSubTitle());
        helper.setText(R.id.tv_date, item.getDate());
        SwipeMenuLayout smlLayout = helper.getView(R.id.sml_layout);
        helper.getView(R.id.tv_top).setOnClickListener(v -> {
            //置顶
            List<SimpleEntity> entities =  getData();
            SimpleEntity entity = entities.remove(helper.getLayoutPosition());
            entities.add(0,entity);
            notifyDataSetChanged();
            smlLayout.quickClose();
        });
        helper.getView(R.id.tv_delete).setOnClickListener(v -> {
            // 删除
            remove(helper.getLayoutPosition());
            smlLayout.quickClose();
        });
    }
}
